package game.actor
{
	import away3d.containers.*;
	
	import engine.asset.*;
	import engine.core.*;
	import engine.graphics.anim.*;
	import engine.graphics.vfx.*;
	import engine.loaders.*;
	import engine.math.*;
	
	import flash.display.*;
	
	import game.*;
	import game.asset.*;
	import game.core.*;
	//import game.messages.gamedata.*;
	import game.messages.inventory.*;
	import game.messages.quest.*;
	import game.messages.simulation.*;
	import game.network.*;
	import game.quest.*;
	import game.scene.*;
	//import game.tools.*;
	import game.ui.core.*;
	
	public class RxActorState extends RxActor
	{
		protected var m_reactFlashTime:Number = 0;
		protected var m_colorFlashTime:Number = 0;
		protected var m_colorFlashR:Number = 1;
		protected var m_colorFlashG:Number = 1;
		protected var m_colorFlashB:Number = 1;
		protected var m_colorFlashA:Number = 1;
		private var m_questVFXState:int = 0;
		private var m_questVFX:RxWorldFXChain;
		private var m_questData:Vector.<RxQuestNPCData>;
		private var m_activeQuestData:RxQuestNPCData = null;
		protected var m_idleSequenceName:String = "seqIdle";
		protected var m_footStepTime:Number = 0;
		protected var m_footStepIndex:int = 0;
		protected var m_moveDelay:Number;
		protected var m_heldTimer:Number = 0;
		protected var m_newPathDest:int = 0;
		protected var m_receivedNode:int = -1;
		protected var m_receivedNodeRunning:int = 0;
		protected var m_receivedNodeInputSequenceNumber:int;
		protected var m_receivedSequence:String = null;
		private var m_coolDown:Object;
		protected var m_attackTimer:Number = 0;
		protected var m_stunTimer:Number = 0;
		private var m_critDeath:Boolean = false;
		protected var m_origShadowPlaneX:Number = 0;
		protected var m_origShadowPlaneZ:Number = 0;
		private var m_auraType:String;
		private var m_auraVFX:RxWorldFXChain;
		private var m_receivingAuraFrom:Vector.<int>;
		private var m_auraSubjectVFXName:String = null;
		private var m_auraSubjectVFX:RxWorldFXChain;
		protected var m_lastState:RxState = null;
		protected var m_lastTransition:String = null;
		protected var m_requestPath:Boolean = true;
		protected var m_pathDelta:Number = 0;
		protected var m_local:Boolean = true;
		protected var m_simPosition:RxVector4;
		protected var m_simDebugSprite:Sprite;
		private var m_debugSpot:Sprite;
		private var m_pickObject:RxLoader3D;
		private var m_pickSequence:RxSequence;
		private var m_pickOn:Boolean;
		private var m_actorIndex:int = -1;
		protected var m_inventory:RxInventory;
		private var m_lastConfigured:Boolean;
		private var m_inventoryPlayerIndex:int = -1;
		private var m_sequenceAnimation:String = null;
		private var m_attackAnimation:String = null;
		private var m_attackTransition:String = null;
		private var m_lastAnimationPos:RxVector4;
		private var m_lastRealPos:RxVector4;
		protected var m_immovable:int;
		protected var m_targetOffset:RxVector4;
		protected var m_currentOffset:RxVector4;
		protected var m_targetAngle:Number = 0;
		protected var m_currentAngle:Number = 0;
		private var m_loadHandle:int;
		protected var m_receivedRunActor:RxActor = null;
		protected var m_receivedRunActorNode0:int;
		protected var m_receivedRunActorNode1:int;
		protected var m_receivedRunActorAttackNodeIndex:int;
		protected var m_receivedRunActorAbility:String;
		protected var m_receivedRunActorAbilityIndex:int;
		protected var m_receivedRunActorNodeInputSequenceNumber:int;
		protected var m_receivedXPEvent:Boolean = false;
		protected var m_receivedXP:uint;
		protected var m_receivedLevel:uint;
		protected var m_receivedAttackActor:RxActor;
		protected var m_receivedAttackActorAbility:String;
		protected var m_receivedAttackActorAbilityIndex:int;
		protected var m_receivedAttackActorInputSequenceNumber:int;
		protected var m_receivedAttackActorAttackNodeIndex:int;
		private static const NUM_PATH_REQUESTS_PER_FRAME:int = 1;
		private static var s_requestsRemaining:int = 0;
		private static var s_requestQueue:Array = new Array();
		public static var s_targetPathTime:int = 0;
		private static var s_isSim:Boolean = false;
		private static const s_inventoryLocationToCharacterPartSlot:Array = new Array();
		
		public function RxActorState(phase:int, type:int, name:String = null, debugColor:int = 8421504)
		{
			this.m_questData = new Vector.<RxQuestNPCData>;
			this.m_coolDown = {};
			this.m_receivingAuraFrom = new Vector.<int>;
			this.m_inventory = new RxInventory();
			this.m_lastAnimationPos = new RxVector4();
			this.m_lastRealPos = new RxVector4();
			this.m_targetOffset = new RxVector4();
			this.m_currentOffset = new RxVector4();
			super(phase, type, name, 65280);
			m_specialAbility = new Array(null, null, null, null, null);
		}
		
		public static function PathRequestUpdate() : void
		{
			if (s_requestQueue.length > s_requestsRemaining)
			{
				s_requestQueue.splice(0, s_requestsRemaining);
			}
			else
			{
				s_requestQueue.length = 0;
			}
			s_requestsRemaining = NUM_PATH_REQUESTS_PER_FRAME;
		}
		
		public static function AdjustDisplayPositions() : void
		{
			/*
			var _loc_1:Number = NaN;
			var _loc_3:Number = NaN;
			var _loc_6:Number = NaN;
			var _loc_7:int = 0;
			var _loc_8:int = 0;
			var _loc_9:int = 0;
			var _loc_10:RxActorState = null;
			var _loc_11:RxActorState = null;
			var _loc_19:Array = null;
			var _loc_20:Number = NaN;
			var _loc_21:Number = NaN;
			var _loc_22:Number = NaN;
			var _loc_23:Number = NaN;
			var _loc_24:Vector.<RxEntity> = null;
			var _loc_25:int = 0;
			var _loc_26:int = 0;
			var _loc_27:Number = NaN;
			var _loc_28:Boolean = false;
			var _loc_29:RxVector4 = null;
			var _loc_30:Boolean = false;
			var _loc_31:RxVector4 = null;
			var _loc_32:Boolean = false;
			var _loc_33:int = 0;
			var _loc_34:RxActorState = null;
			var _loc_35:Number = NaN;
			var _loc_36:RxLoader3D = null;
			_loc_1 = 4;
			var _loc_2:* = _loc_1 * _loc_1;
			_loc_3 = 80;
			var _loc_4:* = _loc_3 * _loc_3;
			var _loc_5:* = _loc_3 * 2;
			var _loc_12:* = new Array();
			var _loc_13:* = new Array();
			var _loc_14:* = new Array(RxEntityType.ENTITY_TYPE_HERO, RxEntityType.ENTITY_TYPE_ENEMY, RxEntityType.ENTITY_TYPE_NONCOMBAT);
			var _loc_15:* = new Vector.<RxEntity>;
			_loc_7 = 0;
			while (_loc_7 < _loc_14.length)
			{
				
				_loc_24 = RxEntity.FindByType(_loc_14[_loc_7]);
				for each (_loc_10 in _loc_24)
				{
					
					if (!_loc_10.isVisible() || _loc_10.m_health <= 0)
					{
						continue;
					}
					_loc_13.push(new Array(_loc_10));
					_loc_12.push(_loc_3);
					_loc_10.m_targetOffset.x = 0;
					_loc_10.m_targetOffset.y = 0;
					_loc_10.m_targetOffset.z = 0;
					_loc_15.push(_loc_10);
				}
				_loc_7++;
			}
			var _loc_16:* = RxVector4.PoolAlloc();
			var _loc_17:* = RxVector4.PoolAlloc();
			var _loc_18:int = 1;
			for each (_loc_10 in _loc_15)
			{
				
				_loc_7 = _loc_18;
				while (_loc_7 < _loc_13.length)
				{
					
					if (_loc_13[_loc_7] != null)
					{
						_loc_8 = 0;
						while (_loc_8 < _loc_13[_loc_7].length)
						{
							
							_loc_11 = _loc_13[_loc_7][_loc_8];
							_loc_6 = RxVector4.DistanceSquared3(_loc_10.GetPos(), _loc_11.GetPos());
							if (_loc_6 <= _loc_4)
							{
								_loc_13[_loc_7].push(_loc_10);
								_loc_25 = _loc_18 - 1;
								if (_loc_13[_loc_25] != null)
								{
									_loc_9 = 1;
									while (_loc_9 < _loc_13[_loc_25].length)
									{
										
										_loc_13[_loc_7].push(_loc_13[_loc_25][_loc_9]);
										_loc_9++;
									}
								}
								_loc_13[_loc_25] = null;
								break;
							}
							_loc_8++;
						}
					}
					_loc_7++;
				}
				_loc_18++;
			}
			_loc_19 = new Array();
			_loc_7 = 0;
			while (_loc_7 < _loc_13.length)
			{
				
				if (_loc_13[_loc_7] != null && _loc_13[_loc_7].length > 1)
				{
					_loc_19.push(_loc_13[_loc_7]);
				}
				_loc_7++;
			}
			_loc_7 = 0;
			while (_loc_7 < _loc_19.length)
			{
				
				_loc_16.Copy(_loc_19[_loc_7][0].GetPos());
				_loc_8 = 1;
				while (_loc_8 < _loc_19[_loc_7].length)
				{
					
					RxVector4.Add(_loc_16, _loc_16, _loc_19[_loc_7][_loc_8].GetPos());
					_loc_8++;
				}
				RxVector4.DivScalar(_loc_16, _loc_16, Number(_loc_19[_loc_7].length));
				_loc_26 = -1;
				_loc_28 = false;
				_loc_8 = 0;
				while (_loc_8 < _loc_19[_loc_7].length)
				{
					
					if (_loc_19[_loc_7][_loc_8].m_pathMover.AtPathEnd() == 1 || _loc_19[_loc_7][_loc_8].m_immovable == 2)
					{
						if (_loc_28 == false)
						{
							_loc_26 = _loc_8;
							_loc_27 = _loc_6;
							_loc_28 = true;
						}
					}
					else if (_loc_28 == true)
					{
					}
					_loc_6 = RxVector4.DistanceSquared3(_loc_16, _loc_19[_loc_7][_loc_8].GetPos());
					if (_loc_26 == -1 || _loc_6 < _loc_27)
					{
						_loc_26 = _loc_8;
						_loc_27 = _loc_6;
					}
					_loc_8++;
				}
				_loc_29 = _loc_19[_loc_7][_loc_26].GetPos();
				_loc_8 = 0;
				while (_loc_8 < _loc_19[_loc_7].length)
				{
					
					_loc_30 = false;
					if (_loc_19[_loc_7][_loc_8].m_immovable == 2)
					{
						_loc_30 = true;
					}
					if (_loc_8 != _loc_26 && _loc_30 == false)
					{
						_loc_31 = _loc_29;
						_loc_32 = true;
						_loc_33 = _loc_19[_loc_7].length + 2;
						while (_loc_32 == true && _loc_33 > 0)
						{
							
							_loc_33 = _loc_33 - 1;
							RxVector4.Sub(_loc_17, _loc_19[_loc_7][_loc_8].GetPos(), _loc_31);
							if (_loc_17.MagnitudeSquared3() < 0.0001)
							{
								_loc_17.Copy(_loc_19[_loc_7][_loc_8].GetDirection());
								_loc_17.x = -_loc_17.x;
								_loc_17.z = -_loc_17.z;
							}
							RxVector4.Normalize3(_loc_17, _loc_17);
							RxVector4.MulScalarAdd(_loc_17, _loc_17, _loc_3 * 2, _loc_31);
							_loc_32 = false;
							_loc_9 = 0;
							while (_loc_9 < _loc_19[_loc_7].length)
							{
								
								if (_loc_19[_loc_7][_loc_8].m_pathMover.AtPathEnd() == 1 || _loc_19[_loc_7][_loc_8].m_immovable >= 1)
								{
									if (_loc_19[_loc_7][_loc_8].m_immovable != _loc_19[_loc_7][_loc_9].m_immovable)
									{
									}
								}
								else if (_loc_19[_loc_7][_loc_8].m_immovable > _loc_19[_loc_7][_loc_9].m_immovable)
								{
								}
								_loc_6 = RxVector4.DistanceSquared3(_loc_17, _loc_19[_loc_7][_loc_9].GetPos());
								_loc_35 = _loc_3 * 1.95 * (_loc_3 * 1.95);
								if (_loc_8 != _loc_9 && _loc_6 < _loc_35)
								{
									_loc_31 = _loc_19[_loc_7][_loc_9].GetPos();
									_loc_32 = true;
									break;
								}
								_loc_9++;
							}
						}
						_loc_34 = _loc_19[_loc_7][_loc_8];
						RxVector4.Sub(_loc_34.m_targetOffset, _loc_17, _loc_34.GetPos());
					}
					_loc_8++;
				}
				_loc_7++;
			}
			for each (_loc_10 in _loc_15)
			{
				
				_loc_36 = _loc_10.m_itemModels.GetModel(RxCharacterModels.SLOT_MAIN);
				if (_loc_36 != null)
				{
					RxVector4.Sub(_loc_17, _loc_10.m_targetOffset, _loc_10.m_currentOffset);
					_loc_6 = _loc_17.MagnitudeSquared3();
					if (_loc_6 > _loc_2)
					{
						RxVector4.MulScalar(_loc_17, _loc_17, _loc_1 / Math.sqrt(_loc_6));
					}
					RxVector4.Add(_loc_10.m_currentOffset, _loc_10.m_currentOffset, _loc_17);
					_loc_20 = 1;
					_loc_22 = _loc_10.m_pathMover.GetTotalDistance();
					_loc_21 = _loc_10.m_pathMover.GetDistanceTravelled() * _loc_22;
					_loc_23 = _loc_22 - _loc_21;
					if (_loc_23 < _loc_5)
					{
						_loc_20 = _loc_23 / _loc_5;
					}
					_loc_36.x = _loc_10.GetPos().x + _loc_10.m_currentOffset.x * _loc_20;
					_loc_36.z = _loc_10.GetPos().z + _loc_10.m_currentOffset.z * _loc_20;
				}
			}
			RxVector4.PoolFree(_loc_17);
			_loc_17 = null;
			RxVector4.PoolFree(_loc_16);
			_loc_16 = null;
			return;*/
		}
		
		public function IsConfigured() : Boolean
		{
			//var _loc_1:* = this.m_inventory.IsConfigured() && !RxItemPackageAsset.IsLoading();
			var _loc_1:*;
			if (_loc_1 && !this.m_lastConfigured)
			{
				this.m_lastConfigured = true;
			}
			return _loc_1;
		}
		
		public function WasConfigured() : Boolean
		{
			return this.m_lastConfigured;
		}
	}
}